package cn.sxt.yxl.controller.head;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.sxt.yxl.common.controller.BaseController;
import cn.sxt.yxl.common.util.ConstatFinalUtil;
import cn.sxt.yxl.common.util.PageInfoUtil;
import cn.sxt.yxl.question.pojo.AColumns;
import cn.sxt.yxl.question.pojo.AColumnsEnum;
import cn.sxt.yxl.question.pojo.AItems;
import cn.sxt.yxl.question.pojo.AItemsEnum;
import cn.sxt.yxl.question.service.IQuestionService;

/**
 * 不需要登陆的Controller
 * 
 * @author liyazhou
 *
 */
@Controller
public class IndexHeadController extends BaseController
{	
	@Resource
	private IQuestionService questionService;
	/**
	 * 首页
	 * @return
	 */
	@RequestMapping("/main")
	public String main(HttpServletRequest request){
		ConstatFinalUtil.LOGGER.info("---- main ----");
		/*将所有栏目查询出来*/
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("status", AColumnsEnum.STATUS_ENABLE.getStatus());
		List<AColumns> columnsList= questionService.findCondListColumnsService(null, condMap );
		request.setAttribute("columnsList", columnsList);
		return "/head/main";
	}
	/**
	 * 栏目下的测试项目
	 * @return
	 */
	@RequestMapping("/{url}")
	public String itemList(HttpServletRequest request, @PathVariable String  url){
		ConstatFinalUtil.LOGGER.info("---- itemList ----url:{}---",url);
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.clear();
		condMap.put("url", url);
		AColumns columns = questionService.findOneColumnsService(condMap );
		request.setAttribute("columns", columns);
		/*分页查询*/
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		/*查询栏目下的所有测试*/
		condMap.clear();
		
		condMap.put("status", AItemsEnum.STATUS_ENABLE.getStatus());
		condMap.put("columnsId", columns.getId());
		List<AItems> itemsList = this.questionService.findCondListItemsService(pageInfoUtil, condMap);
		/* 测试项列表 */
		request.setAttribute("pageInfoUtil", pageInfoUtil);
		request.setAttribute("itemsList", itemsList);
		return "/head/itemsList";
	}
	/**
	 * 动态header
	 */
	@RequestMapping("/header")
	public String header(HttpServletRequest request){
		/*将所有栏目查询出来*/
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("status", AColumnsEnum.STATUS_ENABLE.getStatus());
		List<AColumns> columnsList= questionService.findCondListColumnsService(null, condMap );
		request.setAttribute("columnsList", columnsList);
		return "/head/header";
	}
}
